package com.zj.study.utils.util;

/**
 * 时间工具
 *
 * @author 赵赳
 * @since 2022/1/20 10:29
 */
public class TimeUtils {

  private static int TEMP = 0;
  private static final StringBuilder SB = new StringBuilder();

  /**
   * 时间单位秒，转换为时分秒
   *
   * @param seconds 秒数
   * @return HH:mm:ss
   */
  public static String secondsToMinutesAndSeconds(int seconds) {
    TEMP = seconds / 3600;
    //时
    SB.append((TEMP < 10) ? "0" + TEMP + ":" : "" + TEMP + ":");
    TEMP = seconds % 3600 / 60;
    // 分
    SB.append((TEMP < 10) ? "0" + TEMP + ":" : "" + TEMP + ":");
    // 秒
    TEMP = seconds % 3600 % 60;
    SB.append((TEMP < 10) ? "0" + TEMP : "" + TEMP);
    return SB.toString();
  }

  /**
   * 时间单位秒，转换为时分
   *
   * @param seconds 秒数
   * @return HH:mm
   */
  public static String secondsToMinutes(int seconds) {
    StringBuilder sb = new StringBuilder();
    //时
    TEMP = seconds / 3600;
    sb.append((TEMP < 10) ? "0" + TEMP + ":" : "" + TEMP + ":");
    // 分
    TEMP = seconds % 3600 / 60;
    sb.append((TEMP < 10) ? "0" + TEMP : "" + TEMP);
    return sb.toString();
  }


}
